<template>
	<view class="content">
		<view class="headerBox">
			<image :src="proxy.serverimageUrl + 'login/headerbg.png'" mode=""></image>
		</view>
		<view class="Inputbox">
			<image @click="scanCode" class="code" :src="proxy.serverimageUrl + 'login/code.png'" mode=""></image>
			<!-- 空view 中线占位 -->
			<view class="line">
			</view>
			<view class="inputbox">
				<uni-easyinput v-model="inpvalue" @confirm="confirm" placeholder="学校编码"></uni-easyinput>
			</view>
		</view>
		<up-button type="primary" @click="confirm" class="determinebtn">确定</up-button>
	
	</view>
</template>

<script setup>
	import {
		SchoolIdBySchoolNo,
		getTips
	} from '@/utils/api.js'
	import {
		ref,
		getCurrentInstance
	} from "vue"
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'
	onLoad((o)=>{
		console.log(o,'o............................');
		if(o.schoolNo){
			// getSchoolIdBySchoolNo(o)
		}
		gettips()
	})
	const show = ref(true)
	const {
		proxy,
		ctx
	} = getCurrentInstance()
	const inpvalue = ref('')
	const confirm = () => {
		let params = {
			schoolNo:inpvalue.value
		}
		getSchoolIdBySchoolNo(params)
	}
	/*弹窗关闭事件*/
	const close = () =>{
		show.value = false
	}
	const tipsdata = ref({})
	const gettips = () =>{
		getTips().then(res=>{
			console.log(res)
			tipsdata.value = res.data[0]
		})
	}
	/* 点击扫码 */
	const scanCode = () => {
		console.log(1);
		uni.scanCode({
			scanType: ["qrCode"],
			success: (res) => {
				console.log(res);
				if (res.result) {
					// const val = JSON.parse(res.result);
					let arr = res.result.split('=')
					console.log(arr);
					let params = {
						schoolNo:arr[1]
					}
					getSchoolIdBySchoolNo(params)
				} else {
					console.log('请重新扫描');
					return false;
				}
			},
			fail: (res) => {
				console.log('未识别到二维码');
			}
		})
	}
	const GoIndex = () => {
		uni.switchTab({
			url: '/pages/Home/index'
		})
	}

	const getSchoolIdBySchoolNo = (data) => {
		SchoolIdBySchoolNo(data).then(res => {
			if (res.code === 200) {
				console.log(res);
				//设置全局变量信息
				uni.setStorageSync('sid',res.data)
				GoIndex()
			}
		})
	}
</script>

<style lang="scss" scoped>
	.content {
		.headerBox {
			position: relative;
			z-index: 1;

			image {
				width: 100%;
				height: 780rpx;
			}
		}

		.Inputbox {
			position: relative;
			z-index: 2;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: -74rpx auto 0;
			width: 670rpx;
			height: 120rpx;
			background: #F2F2F2;
			border-radius: 20rpx;
			box-sizing: border-box;
			padding: 36rpx 27rpx;

			.code {
				width: 48rpx;
				height: 48rpx;
			}

			.line {
				width: 2rpx;
				height: 66rpx;
				background: #C6C6C6;
			}

			.inputbox {
				width: 80%;
			}

			::v-deep .uni-easyinput__content {
				background: transparent !important;

				.uni-easyinput__content-input {
					padding-left: 0 !important;
				}
			}

			::v-deep .is-input-border {
				border: none;
			}
		}

		::v-deep .u-button {
			margin: 49rpx auto;
			width: 670rpx;
			height: 120rpx;
			background: #013CAA;
			border-radius: 20rpx;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
		}
		::v-deep .u-popup__content{
			width: 90%;
			padding: 50rpx 30rpx 30rpx;
			.ScrollView{
				margin-top: 10rpx;
				height: 700rpx;
				font-size: 28rpx;
			}
		}
		.btnbox{
			width: 100%;
			height: 100rpx;
			::v-deep .u-button{
				width:100% !important;
				height: 100% !important;
			}
		}
		.contactBox{
			font-size: 28rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			.btn {
				padding: 0;
				background: #ffffff;
				font-size: 28rpx;
				margin: 0;
				margin-left: 10rpx;
				color: #2381fe;
			}
			
			.btn::after {
				border: none;
			}
		}
	}
</style>